Skip to content

fix: sync to x replace fuser with mtime check#151

Merged
otenim merged 4 commits intodevelop/r36.4.0from
fix/sync-to-x-replace-fuser-with-mtime-check
Apr 23, 2026
Merged

fix: sync to x replace fuser with mtime check#151
otenim merged 4 commits intodevelop/r36.4.0from
fix/sync-to-x-replace-fuser-with-mtime-check

Conversation

@citruscosmos
Copy link
Copy Markdown
Contributor

Description

This PR replaces the fuser command with an mtime (modification time) check in the sync-to-x data synchronization process.

Previously, using fuser caused significant slowdowns when operating over network file systems (NFS). Using an mtime-based check provides a much more efficient way to determine if a file is still actively being written to.

Additionally, this PR includes the following updates:

  • Configurable Active-File Threshold: The threshold for determining an active file based on mtime is now configurable via an Ansible parameter.
  • Transfer Bandwidth Limitation Fix: Adjusted the rsync bandwidth limit (increased from 100m to 200m) to resolve transfer bottlenecks.

How to verify

  1. Deploy the updated sync-to-x configuration.
  2. Initiate a data recording session that triggers the synchronization process.
  3. Observe the system resource usage and ensure there are no slowdowns or hangs associated with NFS file checks.
  4. Check the transfer speeds with both a NAS and an external SSD to confirm the bandwidth limit fix is working as expected (up to 200m).

Improvements

  • Eliminates NFS-related slowdowns by removing the fuser dependency.
  • Improves the flexibility of the synchronization service by making the mtime threshold configurable.
  • Resolves previous transfer bandwidth limitations, allowing for faster data synchronization to external devices (NAS and SSD).

Limitations

  • None identified.

citruscosmos and others added 3 commits April 10, 2026 14:35
fuser scans /proc/*/fd for all processes and resolves each symlink via
stat(), which causes excessive NFS round-trips when destinations include
a NAS mount. This results in severe per-file latency inside the transfer
loop.

Replace the fuser-based open-file check with a modification time check
using stat -c %Y. Files modified within the last 10 seconds are
considered active and skipped. This avoids any NFS network I/O for the
active-file guard while remaining reliable for the mcap recording use case.
Replace the hardcoded 10s mtime guard with a configurable parameter
sync_to_x_active_file_threshold_sec (default: 30s). This allows operators
to tune how long after recording ends a file is held back from transfer.
Verified on both NAS and external SSD hardware.

How to verify:
Check transfer speed with NAS and external SSD.

Improvements:
Resolved the transfer bandwidth limitation issue by adjusting the rsync bandwidth limit to 200m.

Limitations:
None.
@citruscosmos citruscosmos requested a review from otenim April 21, 2026 04:35
@citruscosmos citruscosmos changed the title Fix/sync to x replace fuser with mtime check fix/sync to x replace fuser with mtime check Apr 21, 2026
@citruscosmos citruscosmos changed the title fix/sync to x replace fuser with mtime check fix: sync to x replace fuser with mtime check Apr 21, 2026
Copy link
Copy Markdown
Collaborator

@otenim otenim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request: fix stat failure fallback in the active-file check

file_mtime=$(stat -c %Y "$mcap_file" 2>/dev/null || echo 0)
now=$(date +%s)
if [ $((now - file_mtime)) -lt {{ sync_to_x_active_file_threshold_sec }} ]; then
    continue
fi

When stat fails, file_mtime falls back to 0, so now - 0 is a huge number and the condition is false — the file is not skipped and the script proceeds to rsync, then rm -f on success.

Could you change the fallback to skip on stat failure instead? e.g.

if ! file_mtime=$(stat -c %Y "$mcap_file" 2>/dev/null); then
    echo "Skipping (stat failed): $mcap_file"
    continue
fi
now=$(date +%s)
if [ $((now - file_mtime)) -lt {{ sync_to_x_active_file_threshold_sec }} ]; then
    echo "Skipping recently modified file (active within {{ sync_to_x_active_file_threshold_sec }}s): $mcap_file"
    continue
fi

The file will be retried on the next timer tick, which is the safer default.

When stat fails, the previous fallback (|| echo 0) caused now-0 to
be a large number, bypassing the active-file guard and allowing rsync
followed by rm -f on a file whose state was unknown. The file is now
skipped with a log message and retried on the next timer tick.
@citruscosmos
Copy link
Copy Markdown
Contributor Author

@otenim
Thank you for the feedback! I have addressed the issue and confirmed that the nominal case is working as expected.
If there are no further concerns, could you please go ahead and merge this?

@otenim otenim merged commit 707815e into develop/r36.4.0 Apr 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants